package cn.ld.module.ai.dal.mapper.knowledge;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentPageInVO;
import cn.ld.module.ai.dal.entity.knowledge.AiKnowledgeSegmentEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * AI 知识库-分片 Mapper
 *
 * @author xiaoxin
 */
@Mapper
public interface AiKnowledgeSegmentMapper extends BaseMapperX<AiKnowledgeSegmentEntity> {

    default PageResult<AiKnowledgeSegmentEntity> selectPage(AiKnowledgeSegmentPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<AiKnowledgeSegmentEntity>()
                .eq(AiKnowledgeSegmentEntity::getDocumentId, inVO.getDocumentId())
                .eqIfPresent(AiKnowledgeSegmentEntity::getStatus, inVO.getStatus())
                .likeIfPresent(AiKnowledgeSegmentEntity::getContent, inVO.getKeyword())
                .orderByDesc(AiKnowledgeSegmentEntity::getId));
    }

    default List<AiKnowledgeSegmentEntity> selectListByVectorIds(List<String> vectorIdList) {
        return selectList(new LambdaQueryWrapperX<AiKnowledgeSegmentEntity>()
                .in(AiKnowledgeSegmentEntity::getVectorId, vectorIdList)
                .orderByDesc(AiKnowledgeSegmentEntity::getId));
    }

}
